package com.code.coinprice.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.code.coinprice.mappers.CoinPriceSourceMapper;
import com.code.coinprice.models.CoinPriceSource;
import com.code.coinprice.services.CoinPriceSourceService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CoinPriceSourceServiceImpl implements CoinPriceSourceService {

    private final CoinPriceSourceMapper coinPriceSourceMapper;

    public CoinPriceSourceServiceImpl(CoinPriceSourceMapper coinPriceSourceMapper) {
        this.coinPriceSourceMapper = coinPriceSourceMapper;
    }

    @Override
    public CoinPriceSource getCoinPriceSourceBySource(String source) {
        QueryWrapper<CoinPriceSource> wrapper = new QueryWrapper<>();
        wrapper.eq("source", source);
        return coinPriceSourceMapper.selectOne(wrapper);
    }

    @Override
    public CoinPriceSource getCoinPriceSourceById(Integer id) {
        QueryWrapper<CoinPriceSource> wrapper = new QueryWrapper<>();
        wrapper.eq("id", id);
        return coinPriceSourceMapper.selectOne(wrapper);
    }

    @Override
    public List<CoinPriceSource> getCoinPriceSourceList() {
        return coinPriceSourceMapper.selectList(null);
    }
}
